<template>
<div>
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="商品名称">
      <el-input v-model="form.name" placeholder="请输入商品名称"></el-input>
    </el-form-item>
    <el-form-item label="商品重量">
      <el-input v-model="form.weight" placeholder="请输入商品重量"></el-input>
    </el-form-item>
    <el-form-item label="发布日期">
      <el-input v-model="form.issueDate" placeholder="请输入发布日期"></el-input>
    </el-form-item>
    <el-form-item label="价格">
      <el-input v-model="form.price" placeholder="请输入价格"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="success" plain @click="onSubmit">发布商品</el-button>
      <el-button type="danger" plain @click="dialogVisible = true">重新填写</el-button>
    </el-form-item>
  </el-form>
<!--对话框-->
  <el-dialog title="提醒" :visible.sync="dialogVisible" width="30%" >
    <span>确定重新填写？</span>
    <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="reset()">确 定</el-button>
  </span>
  </el-dialog>
<router-view></router-view><!--子路由-->
</div>
</template>

<script>
import axios from "axios";

export default {
  name: "Add",
  data(){
    return{
      form: {
        name: '',
        weight:'',/*商品重量*/
        price:'',
        issueDate:this.currTime(),
      },
      dialogVisible: false,
    }
  },
  methods:{
    onSubmit() {
      //向后端发起post请求
      this.form.issueDate=this.currTime();
      // console.log("表单时间"+this.form.issueDate)
      axios.post('http://localhost:8081/shop/addShop',this.form)
        .then((res)=>{
          if(res.data.result){
            this.$message({
              message: '请完善商品图片信息',
              type: 'success'
            });
           this.$router.push('/shopImg')
          }
        })
    },
    currTime() {
      let date = new Date()
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      return year + "-" + month + "-" + day;
    },
    reset(){
      this.dialogVisible=false; /*先隐藏对话框*/
      this.form.name='';
      this.form.weight='';
      this.form.price='';
    },
  },
  computed:{

  }
}
</script>

<style scoped>

</style>
